package roger;
import java.io.FileWriter;
import java.io.IOException;

public class ToXML {
	String xml;
	
	public ToXML(){
		xml = new String();
	}
	
	public void visitGarage(Garage g){
		xml += "<garage>\n";
		xml += "\t<nom>"+ g.nom +"</nom>\n";
		xml += "\t<adresse>"+ g.adresse +"</adresse>\n";
		xml += "\t<capacite>"+ g.getCapacite() +"</capacite>\n";
		xml += "\t<nbRepEnCours>" + g.getNbRepEnCours() +"</nbRepEnCours>\n";
		xml += "\t<reparations>\n";
		for(int i = 0; i < g.getNbRepEnCours(); i++){
			visitReparation(g.getReparation(i));
		}
		xml += "\t</reparations>\n";
		xml += "</garage>\n";
	}
	
	public void visitReparation(Reparation r){
		xml += "\t\t<reparation>\n";
		xml += "\t\t\t<date>"+ r.getDate() +"</date>\n";
		xml += "\t\t\t<motif>"+ r.getMotif() +"</motif>\n";
		xml += "\t\t</reparation>\n";
	}
	
	public void enregistre() throws IOException{
		FileWriter file = new FileWriter("/home2/filieres/mas2iup/lanuelha/Bricoloto.xml");
		file.write(xml);
		file.close();
	}
}
